package main.pmc;

import cn.hutool.core.io.FileUtil;
import cn.hutool.db.Db;
import cn.hutool.db.Entity;
import com.alibaba.fastjson.JSONArray;
import lombok.SneakyThrows;
import utils.SmallTool;
import utils.StringUtil;
import utils.httpclient.HttpClient;
import utils.httpclient.HttpClientConfig;
import utils.httpclient.HttpClientUtil;

import java.io.IOException;
import java.net.URL;
import java.sql.SQLException;
import java.util.*;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import static main.pmc.LocalPmcFileCheck.isCheckDownType;

/**
 * @Author: 葛成瑞
 * @Date: 2025/3/18 17:05
 */
public class Test {
    @SneakyThrows
    public static void main(String[] args) {
        List<Integer> as = new ArrayList<>();
        for (int i = 0; i < 100000; i++) {
            as.add(i);
        }
        ThreadPoolExecutor executor = new ThreadPoolExecutor(
                200,
                300,
                10,
                TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(), new ThreadPoolExecutor.CallerRunsPolicy());
        for (Integer a : as) {
            executor.submit(() -> {
                try {
                    Random random = new Random();
                    int i = random.nextInt(3);
                    Thread.sleep(i * 1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }

            });
        }
        executor.shutdown();
        while (!executor.awaitTermination(5, TimeUnit.SECONDS)) {
            int activeCount = executor.getActiveCount();
            SmallTool.printMess("当前线程数" + activeCount);
            long completedTaskCount = executor.getCompletedTaskCount();
            SmallTool.printMess("已完成任务数" + completedTaskCount);
        }
        System.out.println("任务结束本批次结束");
    }
}
